//
//  LSWTabBarController.m
//  BaiSi
//
//  Created by 李善武 on 16/5/9.
//  Copyright © 2016年 李善武. All rights reserved.
//

#import "LSWTabBarController.h"
#import "LSWNavigationController.h"
#import "LSWTabBar.h"
#import "LSWEssenceViewController.h"
#import "LSWMeTableViewController.h"
#import "LSWFriendTrendViewController.h"
#import "LSWNewTopicViewController.h"

#import "UIImage+Render.h"
@interface LSWTabBarController ()

@end

@implementation LSWTabBarController

+ (void)load{
   // 获取当前的tabBarItem
    UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
    
    // 设置富文本属性(颜色，字体)
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    dict[NSForegroundColorAttributeName] = [UIColor blackColor];
    [item setTitleTextAttributes:dict forState:UIControlStateSelected];
    
    NSMutableDictionary *dictText = [[NSMutableDictionary alloc]init];
    dictText[NSFontAttributeName] = [UIFont systemFontOfSize:13.0];
    [item setTitleTextAttributes:dictText forState:UIControlStateNormal];
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 设置导航控制器
    [self setupAllChildeVC];
    [self setupTabBar];
    [self setAllTitleBtn];
}


// 添加所有子控制器
- (void)setupAllChildeVC{
    // 精华
    LSWEssenceViewController *essence = [[LSWEssenceViewController alloc]init];
    essence.view.backgroundColor = [UIColor redColor];
    LSWNavigationController *nav1 = [[LSWNavigationController alloc]initWithRootViewController:essence];
    [self addChildViewController:nav1];
    
    // 新帖
    LSWNewTopicViewController *newTopic = [[LSWNewTopicViewController alloc]init];
    newTopic.view.backgroundColor = [UIColor greenColor];
    LSWNavigationController *nav2 = [[LSWNavigationController alloc]initWithRootViewController:newTopic];
    [self addChildViewController:nav2];
    
    // 发布
//    LSWAddViewController *adVC = [[LSWAddViewController alloc]init];
//    adVC.view.backgroundColor = [UIColor yellowColor];
//    [self addChildViewController:adVC];
    
    // 关注
    LSWFriendTrendViewController *friendTrend = [[LSWFriendTrendViewController alloc]init];
    //friendTrend.view.backgroundColor = [UIColor blueColor];
    LSWNavigationController *nav3 = [[LSWNavigationController alloc]initWithRootViewController:friendTrend];
    [self addChildViewController:nav3];
    
    // 我
    LSWMeTableViewController *me = [[LSWMeTableViewController alloc]init];
    me.view.backgroundColor = [UIColor brownColor];
    LSWNavigationController *nav4 = [[LSWNavigationController alloc]initWithRootViewController:me];
    [self addChildViewController:nav4];
}

// 自定义tabBar
- (void)setupTabBar{
    LSWTabBar *tabBar = [[LSWTabBar alloc]init];
    // 利用KVC底层替换系统的tabBar
    [self setValue:tabBar forKey:@"tabBar"];
    
}

// 设置标题按钮内容
- (void)setAllTitleBtn{
    
    // 精华
    UINavigationController *nav0 = self.childViewControllers[0];
    nav0.tabBarItem.title = @"精华";
    nav0.tabBarItem.image = [UIImage imageNamed:@"tabBar_essence_icon"];
    nav0.tabBarItem.selectedImage = [UIImage renderImageWithOriginalImage:@"tabBar_essence_click_icon"];
    
    // 新帖
    UINavigationController *nav1 = self.childViewControllers[1];
    nav1.tabBarItem.title = @"新帖";
    nav1.tabBarItem.image = [UIImage imageNamed:@"tabBar_new_icon"];
    nav1.tabBarItem.selectedImage = [UIImage renderImageWithOriginalImage:@"tabBar_new_click_icon"];

    
    // 关注
    UINavigationController *nav2 = self.childViewControllers[2];
    nav2.tabBarItem.title = @"关注";
    nav2.tabBarItem.image = [UIImage imageNamed:@"tabBar_friendTrends_icon"];
    nav2.tabBarItem.selectedImage = [UIImage renderImageWithOriginalImage:@"tabBar_friendTrends_click_icon"];
    
    // 我
    UINavigationController *nav3 = self.childViewControllers[3];
    nav3.tabBarItem.title = @"我";
    nav3.tabBarItem.image = [UIImage imageNamed:@"tabBar_me_icon"];
    nav3.tabBarItem.selectedImage = [UIImage renderImageWithOriginalImage:@"tabBar_me_click_icon"];
}

@end
